package com.trkj.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trkj.dao.UserDao;
import com.trkj.entity.RoleEntity;
import com.trkj.entity.UserEntity;
import com.trkj.entity.UserRoleEntity;
import com.trkj.util.BeanTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService{
    //查询员工
    @Autowired
    private UserDao userDao;
    @Override
    @Cacheable(cacheNames = "allusers",key = "#currentPage+','+#pageSize")
    public PageInfo<UserRoleEntity> UserList(UserRoleEntity userRoleEntity , int currentPage, int pageSize){
        PageHelper.startPage(currentPage,pageSize);
        List<UserRoleEntity> List= this.userDao.UserList(userRoleEntity);
        PageInfo<UserRoleEntity> pageDto=new PageInfo<>(List);
        log.debug("123:{}",pageDto);
        return pageDto;
    }
    @Override
    public List<RoleEntity> RoleList(){
        return userDao.RoleList();
    }
    @Override
    @Transactional
    public List<UserEntity> MaxUserId(){
        return userDao.MaxUserId();
    }
    //添加员工表
    @Override
    @Transactional
    public boolean AddUser(UserEntity userEntity){
        return userDao.AddUser(userEntity);
    }
    //根据员工id进行查询
    @Override
    public List<UserEntity> ChaUseridList(int user_id){
        return userDao.ChaUseridList(user_id);
    }
    //修改员工表
    @Override
    @Transactional
    public boolean UpdUser(UserEntity userEntity){
        return userDao.UpdUser(userEntity);
    }
    //添加角色表
    @Override
    @Transactional
    public boolean AddRole(RoleEntity roleEntity){
        return userDao.AddRole(roleEntity);
    }
    //添加员工权限表
    @Override
    @Transactional
    public boolean AddUserRole(UserRoleEntity userRoleEntity){
        return userDao.AddUserRole(userRoleEntity);
    }
    @Override
    @Transactional
    public boolean UpdUserRole(UserRoleEntity userRoleEntity){
        return userDao.UpdUserRole(userRoleEntity);
    }
    @Override
    public boolean DelUserRole(int user_id){
        return userDao.DelUserRole(user_id);
    }
    @Override
    public boolean DelUser(int user_id){
        return userDao.DelUser(user_id);
    }
    @Override
    public List<UserEntity> ZhiXingRen(){
        return userDao.ZhiXingRen();
    }
}
